package com.note.kafka;


import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

/**
 * <p>【描述】：定时推送数据</p>
 * <p>【作者】: BeyMax</p>
 * <p>【日期】: 2020/1/2</p>
 **/
@Slf4j
@Component
public class PushData {


    @Value("${tablePushSwitch}")
    boolean tablePushSwitch;
    @Value("${graphPushSwitch}")
    boolean graphPushSwitch;

    // 手动推送数据相关
    @Value("${push.switch}")
    boolean handPushSwitch;
    @Value("${push.type}")
    String handPushType;
    @Value("${push.date}")
    String handPushDate;
    @Value("${push.datasetId}")
    String handPushDatasetId;

    public void handPush() {
        if (handPushSwitch) {

        }
    }

    @Scheduled(cron = "${graphPushTime}")
    public void run() {

        if (graphPushSwitch) {
            log.error("开始执行graph数据推送！！！！！！！！！！！！！");
            String yesterdayDate = getYesterdayDate();

            log.error("============================ [graph]昨天没有数据！！！ ========================");
            log.error("============================ [graph]昨天没有数据！！！ ========================");
            log.error("============================ [graph]昨天没有数据！！！ ========================");
            log.error("============================ [graph]重要的事情说三遍！！！ ========================");
        }
        log.error("============================ [graph]推送数据未开启 ========================");
    }

    /**
     * <p>【描述】：推送表格展示的数据</p>
     * <p>【方法】：pushTableData</p>
     * <p>【参数】: []</p>
     * <p>【作者】: BeyMax</p>
     * <p>【日期】: 2020/1/14</p>
     **/
    @Scheduled(cron = "${tablePushTime}")
    public void pushTableData() {
        if (tablePushSwitch) {
            log.error("开始执行table推送！！！！！！！！！！！！！");
        }
        log.error("===================  [table]推送数据未开启 ========================");
    }

    /**
     * <p>【描述】：获取昨天的日期</p>
     * <p>【方法】：getYesterdayDate</p>
     * <p>【参数】: []</p>
     * <p>【作者】: BeyMax</p>
     * <p>【日期】: 2020/1/3</p>
     **/
    public String getYesterdayDate() {
        Calendar cal = Calendar.getInstance();
        cal.add(Calendar.DATE, -1);
        Date d = cal.getTime();
        SimpleDateFormat sp = new SimpleDateFormat("yyyyMMdd");
        String yesterday = sp.format(d);
        return yesterday;
    }


}
